package com.charlotte.gupao.study.provider;

import com.charlotte.gupao.study.support.AmqpConnection;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author junjie.ding
 * @date 2020/10/29 21:19
 * @description TODO
 */
public class TopicProvider {

    private static final String QUEUE_NAME = "TOPIC_QUEUE_NAME";

    private static final String EXCHANGE_NAME = "TOPCI_EXCHANGE_NAME";

    public static void main(String[] args) {
        Connection conn;
        final Channel channel;
        try {
            conn = AmqpConnection.getConnection();
            // 创建消息通道
            channel = conn.createChannel();

            // 声明队列（默认交换机AMQP default，Direct）
            // String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);

            // 发送消息
            // String exchange, String routingKey, BasicProperties props, byte[] body
            String msg = "消息，编号：";
            for (int i = 0; i < 5; i++){
                channel.basicPublish(EXCHANGE_NAME, "topic.msg", null, (msg + i).getBytes());
            }

            channel.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {

        }
    }
}
